import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../../widgets/text_input.dart';

class AuthInput extends StatefulWidget {
  const AuthInput({
    Key? key,
    this.prefix,
    this.suffix,
    this.controller,
    this.onChange,
    this.hintText,
    this.obscureText,
    this.inputFormatter,
  }) : super(key: key);

  final Widget? prefix;
  final Widget? suffix;
  final TextEditingController? controller;
  final Function(String value)? onChange;
  final String? hintText;
  final bool? obscureText;
  final List<TextInputFormatter>? inputFormatter;

  @override
  State<AuthInput> createState() => _AuthInputState();
}

class _AuthInputState extends State<AuthInput> {
  @override
  Widget build(BuildContext context) {
    return inputDecoration();
  }
  
  Widget inputDecoration({Widget? child}) {
    return Container(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(10.r),
        color: Color(0xFFf3f3f3)
      ),
      padding: EdgeInsets.symmetric(horizontal: 25.w),
      height: 60.h,
      child: Row(
        children: [
          widget.prefix ?? SizedBox(),
          divider(),
          Expanded(
            child: AppTextInput(
              hintText: widget.hintText ?? '',
              controller: widget.controller,
              onChange: widget.onChange,
              obscureText: widget.obscureText,
              inputFormatter: widget.inputFormatter,
            )
          ),
          widget.suffix ?? SizedBox()
        ],
      ),
    );
  }

  Widget divider() {
    return Container(
      margin: EdgeInsets.only(left: 25.w, right: 15.w),
      width: 1.w,
      height: 20.h,
      color: Color(0xFFc6c6c6),
    );
  }
}
